﻿<?xml version="1.0" encoding="UTF-8"?>
<AppletManifest xmlns="http://openiz.org/mobile/applet">
	<info>
		<name>System Settings</name>
		<version>1.0.0.0</version>
		<author>OpenIZ.org Community</author>
		<icon>@drawable/cogs</icon>
		<id>org.openiz.applets.core.settings</id>
		<groupName>Administration</groupName>
		<demand>1.3.6.1.4.1.33349.3.1.5.9.3.10</demand>
	</info>
	<tile size="sm">
		<text>System Settings</text>
		<icon>@drawable/cogs</icon>
	</tile>
	<asset name="index" mimeType="text/html">
		<contentXml>
			<body xmlns="http://www.w3.org/1999/xhtml" ng-controller="ConfigurationController">
				<div class="container">
					<div class="row">
						<div class="col-md-12">
							<div class="panel panel-default">
								<div class="panel-heading">
									<h3 class="panel-title">Realm Settings</h3>
								</div>
								<div class="panel-body">
									<div class="container">
										<div class="row">
											<div class="col-md-12">
												<img src="app://openiz.org/drawable/drk_grid" style="width:64px; height:64px; float:left" />
												<em>A realm is a collection of servers with which the mobile application can interact. In order to join the realm you will
											need to enter the following information about the realm. If your app is already connected to a realm, you may leave the realm using this panel.</em>
											</div>
										</div>
									</div>
									<form name="realmForm" novalidate="novalidate">
										<div class="input-group">
											<span class="input-group-addon" id="deviceNameLabel">Device Name:</span>
											<input ng-model="realm.deviceName" ng-required="true" placeholder="tabletid" ng-pattern="/^[A-Z][A-Z.0-9-]+$/i" class="form-control" type="text" name="deviceName" id="deviceName" aria-describedby="deviceNameLabel" />
											<span class="input-group-addon">
												<span class=" glyphicon glyphicon-phone">
												</span>
											</span>
										</div>
										<div class="input-group">
											<span class="input-group-addon" id="realmServerLabel">Realm:</span>
											<input ng-model="realm.address" ng-required="true" placeholder="https://demo.openiz.org:8443/realm" ng-pattern="/^https:\/\/([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?$/i" class="form-control" type="url" name="realmServer" id="realmServer" aria-describedby="realmServerLabel" />
											<span class="input-group-addon">
												<span class=" glyphicon glyphicon-globe">
												</span>
											</span>
										</div>
										<div class="btn-group pull-right">
											<button class="btn-danger btn" ng-disabled="realm.address !== null" ng-click="leaveRealm(realm)">
												<span class="glyphicon glyphicon-resize-full">
												</span> Leave Realm</button>
											<button class="btn-primary btn" ng-click="joinRealm(realm)" ng-disabled="realmForm.$invalid">Join Realm <span class="glyphicon glyphicon-resize-small"></span></button>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
				<form name="configurationForm" novalidate="novalidate">
					<div class="container">
						<!-- Security Settings -->
						<div class="row">
							<div class="col-md-12">
								<div class="panel panel-default">
									<div class="panel-heading">
										<h3 class="panel-title">
											<a href="#securitySettings" data-toggle="collapse">Security Settings</a>
										</h3>
									</div>
									<div class="panel-collapse collapse" id="securitySettings">
										<div class="panel-body">
											<div class="container">
												<div class="row">
													<div class="col-md-12">
														<img src="app://openiz.org/drawable/drk_shield" style="width:64px; height:64px; float:left" />
														<em>Use this area to configure security settings related to OpenIZ</em>
													</div>
												</div>
											</div>
											<div class="input-group">
												<span class="input-group-addon" id="dataRetentionLabel">Data Retention Policy:</span>
												<select ng-model="config.security.retention" class="form-control" name="dataRetention" id="dataRetention" aria-describedBy="dataRetentionLabel">
													<option value="any">Store Data Locally</option>
													<option value="requirelocal">Require Local Encryption</option>
													<option value="onlineonly">Online Only</option>
												</select>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- Facility Settings -->
						<div class="row">
							<div class="col-md-12">
								<div class="panel panel-default">
									<div class="panel-heading">
										<h3 class="panel-title">
											<a href="#facilitySettings" data-toggle="collapse">Facility Settings</a>
										</h3>
									</div>
									<div class="panel-collapse collapse" id="facilitySettings">
										<div class="panel-body">
											<div class="container">
												<div class="row">
													<div class="col-md-12">
														<img src="app://openiz.org/drawable/drk_facility" style="width:64px; height:64px; float:left" />
														<em>Select the facility/facilities in which this device will be used. This setting controls what data is synchronized.</em>
													</div>
												</div>
											</div>
											<div class="input-group">
												<span class="input-group-addon" id="facilityNameLabel">Facility:</span>
												<select ng-required="true" ng-pattern="/\d+/" data-openiz-tag="select2" multiple="multiple" style="width:100%" ng-model="config.facility.fac" class="form-control" name="dataRetention" id="dataRetention" aria-describedBy="dataRetentionLabel">
													
												</select>
											</div>

										</div>
									</div>
								</div>
							</div>
						</div>

												<div class="row">
							<div class="col-md-12">
								<div class="btn-group pull-right">
									<button class="btn-danger btn" ng-click="close()">
										<span class="glyphicon glyphicon-remove">
										</span> Cancel</button>
									<button class="btn-primary btn" ng-click="save(config)">Save <span class="glyphicon glyphicon-ok"></span></button>
								</div>
							</div>
						</div>
					</div>
				</form>
		        <!-- OpenIZ:Scripts -->
				
			</body>
		</contentXml>
	</asset>
	<asset name="index-controller" mimeType="text/javascript">
		<contentText><![CDATA[
			// angular stuff
			var configApp = angular.module('index', []);

			configApp.controller('ConfigurationController', ['$scope', function ($scope)
			{

				$scope.master = {};

				// leave realm
				$scope.leaveRealm = function(realm)
				{
					OpenIZ.Configuration.leaveRealm(realm);
				}

				// join realm
				$scope.joinRealm = function(realm) {
					OpenIZ.Configuration.joinRealm(realm.address);
				};

				// Close app
				$scope.close = function() {
					OpenIZ.App.close();
				}

				// Save config
				$scope.save = function(config) {
					if(OpenIZ.Configuration.save(config))
						OpenIZ.App.close();
				}

				$scope.reset = function() {
					$scope.user = angular.copy($scope.master);
				};

				$scope.reset();
			}]);

		]]></contentText>
	</asset>
</AppletManifest>